package com.zoro.jianyue.interactor.impl;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.GsonRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.reflect.TypeToken;
import com.zoro.jianyue.bean.ResponseImagesListEntity;
import com.zoro.jianyue.interactor.CommonListInteractor;
import com.zoro.jianyue.lisneter.BaseMultLoadedlistener;
import com.zoro.jianyue.utils.UriHelper;
import com.zoro.jianyue.utils.VolleyHelper;

/**
 * Created by CM-ZR on 2016/1/29.
 */
public class ImagesListInteractorImpl implements CommonListInteractor {
    private BaseMultLoadedlistener<ResponseImagesListEntity> loadedLisneter = null;

    public ImagesListInteractorImpl(BaseMultLoadedlistener<ResponseImagesListEntity>
                                            loadedLisneter) {
        this.loadedLisneter = loadedLisneter;
    }


    @Override
    public void getCommonListData(String requestTag, final int event_tag, String keywords, int
            page) {
        GsonRequest<ResponseImagesListEntity> gsonRequest = new
                GsonRequest<ResponseImagesListEntity>(UriHelper.getInstance().getImageListUrl
                (keywords, page), null, new TypeToken<ResponseImagesListEntity>() {
        }.getType(), new Response.Listener<ResponseImagesListEntity>() {
            @Override
            public void onResponse(ResponseImagesListEntity response) {
                loadedLisneter.onSuccess(event_tag, response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                loadedLisneter.onException(error.getMessage());
            }
        });

        gsonRequest.setShouldCache(true);
        gsonRequest.setTag(requestTag);

        VolleyHelper.getInstance().getRequestQueue().add(gsonRequest);
    }

}
